< previous page page_457 next page >

Page 457
The ComputerInfo class is a good example of using Visual Basic's object-oriented capabilities to your advantage. Not only does it make using the ComputerName APIs easier, but it is also very easy to include in multiple projects. You can also continue to add properties and events to the ComputerInfo class as needed.
Useful API Calls
The best way to learn about the Windows API is to practice. If you look at the WIN32API.TXT file, you'll notice that quite a few API calls are available. The following sections will introduce some of the most interesting ones.
Fun API Calls
The next two API calls you will explore on your tour are both easy to use and fun. The first function, sndPlaySound, allows you to play waveform (.WAV) sound files on the sound card. They have two parameters: the name of the sound file and flags to control how the sound is played. Listing 20.4 shows an example.
Listing 20.4 APIDEMO.ZIPPlaying WAV Files with sndPlaySound
Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal _
                 lpszSoundName As String, ByVal uFlags As Long) As Long

Public Const SND_ALIAS = &H10000    '  name is in WIN.INI or the Registry
Public Const SND_ASYNC = &H1        '  play asynchronously
Public Const SND_SYNC = &H0         '  play synchronously (default)
Public Const SND_NOWAIT = &H2000    '  don't wait if the driver is busy
Public Const SND_LOOP = &H8         '  loop the sound until next sndPlaySound

Sub SoundCheck()
    Dim lRetVal As Long

    lRetVal = sndPlaySound("C:\WINDOWS\MEDIA\CHIMES.WAV", SND_SYNC)
    lRetVal = sndPlaySound("SystemStart", SND_ALIAS + SND_ASYNC + SND_NOWAIT)

 'The alias names of system sounds are listed in the registry together,
 'to find them search for SystemStart

End Sub
All the constants that begin with the prefix SND are listed together and commented in the API text file. The two of most concern are SND_ASYNC and SND_SYNC, which control whether the program will wait until the sound is finished before continuing.
Another API function, SystemParametersInfo, can be used to set the Windows background wallpaper. I used this function with a video capture camera to create a "virtual window office" at work. An example with SystemParametersInfo is shown in Listing 20.5.

 
< previous page page_457 next page >